(function(f, define) {
    define(["./kendo.data"], f);
})(function() {

    (function() {

        (function($) {
            var DataSource = kendo.data.DataSource,
                extend = $.extend,
                HateoasDataSource = DataSource.extend({
                    init: function(options) {
                        if (options.hateoas) {
                            var hateoasOptions = extend({ contentType: "application/hal+json", dataType: "json" }, options.hateoas),
                                u1 = "/" + hateoasOptions.name,
                                u2 = function(request) {
                                    var _links = request._links,
                                        href = _links ? _links.self.href : u1;
                                    return options.batch ? u1 : href;
                                },
                                options = extend(true, {
                                    schema: {
                                        total: function(response) {
                                            return response.page.totalElements;
                                        },
                                        data: function(response) {
                                            return response._embedded ? response._embedded[hateoasOptions.name] : response;
                                        },
                                        groups: function(response) {
                                            return response._embedded ? response._embedded[hateoasOptions.name] : response;
                                        }
                                    },
                                    transport: {
                                        read: extend({ type: "GET", url: u1 }, hateoasOptions),
                                        create: extend({ type: "POST", url: u1 }, hateoasOptions),
                                        update: extend({ type: "PATCH", url: u2 }, hateoasOptions),
                                        destroy: extend({ type: "DELETE", url: u2 }, hateoasOptions),
                                        parameterMap: function(options, operation) {
                                            if (operation !== "read" && options) {
                                                return kendo.stringify(options);
                                            }
                                            return options;
                                        }
                                    }
                                }, options);
                        }
                        DataSource.fn.init.call(this, options);
                    }
                });
            HateoasDataSource.create = function(options) {
                var dataSource = options || {};
                return dataSource instanceof DataSource ? dataSource :
                    new HateoasDataSource(options);
            };
            kendo.data.HateoasDataSource = HateoasDataSource;
        })(window.kendo.jQuery);

    })();

    return window.kendo;

}, typeof define == 'function' && define.amd ? define : function(_, f) {
    f();
});